/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 涛
 * Date: 2023-09-18
 * Time: 18:47
 */

class Student {
    String name;
    int age;
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
}
class Example{
    String str = new String("good");
    char[ ] ch = { 'a' , 'b' , 'c' };
    public static void main(String args[]){
        Example ex = new Example();
        ex.change(ex.str,ex.ch);
        System.out.print(ex.str + " and ");
        System.out.print(ex.ch);
    }
    public void change(String str,char ch[ ]){
        str = "test ok";
        ch[0] = 'g';
    }
}

    String s1="abc"+"def";//1
    String s2=new String (s1);//2
        if(s1.equals(s2))//3
        System.out.println(".equals succeeded");//4
        if(s1==s2)//5
        System.out.println("==succeeded");//6


public class Test {


    public static boolean isAdmin(String userId){
        return userId.toLowerCase()=="admin";
    }
    public static void main(String[] args){
        System.out.println(isAdmin("Admin"));
    }
}
    public static void main16(String[] args) {
        String str = "192\\192\\1\\1";
        String[] result = str.split("\\\\",4);
        for (String s : result) {
            System.out.println(s);
        }
    }
    public static void main15(String[] args) {
        String str = "hello world hello bit";
        String[] result = str.split(" ");
        for (String s:result) {
            System.out.println(s);
        }
        System.out.println("=========================");
        String[] result2 = str.split(" ", 3);
        for (String s2: result2) {
            System.out.println(s2);
        }
    }
    public static void main14(String[] args) {
        //替换字符串
        String s1 = "hello";
        String s2 = "world";
        String s3 = s1.replaceAll("|", "_");
        System.out.println(s3);
        String s4 = s1.replaceFirst("|","_");
        System.out.println(s4);
    }
    public static void main13(String[] args) {
        //格式化
        String s1 = String.format("%d/%d/%d/%d", 1999,9,9,24);
        System.out.println(s1);
    }
    public static void main12(String[] args) {
        //字符串转数组
        String s1 = "hello";
        char[] ch = s1.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            System.out.println(ch[i]);
        }
    }
    public static void main11(String[] args) {
        //大小写转换
        String s1 = "hello";
        String s2 = "HELLO";
        System.out.println(s1.toUpperCase());
        System.out.println(s2.toLowerCase());
    }

    public static void main10(String[] args) {
        //数字转字符串
        String s1 = String.valueOf(19);
        String s2 = String.valueOf(19.9);
        String s3 = String.valueOf(true);
        String s4 = String.valueOf(new Student("小明", 20));

        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);
        System.out.println("=========================");
        //字符串转数字
        int data1 = Integer.parseInt("1234");
        double data2 = Double.parseDouble("12.34");
        System.out.println(data1);
        System.out.println(data2);
    }

    public static void main9(String[] args) {
        String s1 = "abcabcfabcd";
        System.out.println(s1.lastIndexOf('c'));
        System.out.println(s1.lastIndexOf('c', 6));
        System.out.println(s1.lastIndexOf("abc"));
        System.out.println(s1.lastIndexOf("abc", 6));
    }
    public static void main8(String[] args) {
        String s1 = "abcabcfabcd";
        System.out.println(s1.charAt(3));
        System.out.println(s1.indexOf('c'));
        System.out.println(s1.indexOf('b', 2));
        System.out.println("================");
        System.out.println(s1.indexOf("bc"));
        System.out.println(s1.indexOf("bc",2));
        System.out.println("=============");
    }
    public static void main7(String[] args) {
        String s1 = new String("abc");
        String s2 = new String("ac");
        String s3 = new String("ABc");
        String s4 = new String("abcdef");
        System.out.println(s1.compareToIgnoreCase(s2));
        System.out.println(s1.compareToIgnoreCase(s3));
        System.out.println(s1.compareToIgnoreCase(s4));

    }
    public static void main6(String[] args) {
        //有大小写区分
        String s1 = "abc";
        String s2 = "ac";
        String s3 = "abc";
        String s4 = "abcdef";
        System.out.println(s1.compareTo(s2));
        System.out.println(s1.compareTo(s3));
        System.out.println(s1.compareTo(s4));

    }
    public static void main5(String[] args) {
        String s1 = "hello";
        String s2 = "hello";
        String s3 = "Hello";
        System.out.println(s1.equals(s2));//比较的是对象放置的内容
        System.out.println(s1.equals(s3));
    }

    public static void main4(String[] args) {
        int a = 10;
        int b = 10;
        int c = 20;
        System.out.println(a == b);//基本类型变量
        System.out.println(a == c);
        System.out.println("====================");

        String s1 = new String("hello");
        String s2 = new String("hello");
        String s3 = new String("world");
        String s4 = s1;
        System.out.println(s1 == s2);//引用类型变量比较的是对象
        System.out.println(s1 == s3);
        System.out.println(s1 == s4);
    }

    public static void main3(String[] args) {

        System.out.println("hello world".length());
    }
    public static void main2(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = s1;

        System.out.println(s1.length());
        System.out.println(s1.isEmpty());
    }
    public static void main1(String[] args) {
        String s1 = "abcde";
        System.out.println(s1);
        String s2 = new String("abcde");
        System.out.println(s2);
        char array[] = {'a', 'b', 'c', 'd', 'e'};
        String s3 = new String(array);
        System.out.println(s3);
    }
}
